<?php

namespace app\admin\model\shopro\wechat;

use think\Model;


class Msg extends Model
{
    // 表名
    protected $name = 'shopro_wechat_msg';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;
    protected $append = [
        'user_ids_list',
        'user_ids',
    ];

    public function getUserIdsListAttr($value, $data)
    {
        $user_ids_list = [];
        if(!empty($data['user_ids'])){
            $userids = explode(',',$data['user_ids']);
            foreach ($userids as $val) {
                $user_ids_list[] = \app\admin\model\shopro\user\User::where(["id"=>$val])->field('id,nickname')->find();
            }
        }
        return $user_ids_list;
    }
    public function getUserIdsAttr($value, $data)
    {
        $user_ids =[];
        $user_store = \think\Db::name('shopro_wechat_msg')->where('id', $data['id'])->find();
        if(!empty($user_store['user_ids'])){
            $user_ids = array_map('intval', explode(',',$user_store['user_ids']));
        }
        return $user_ids;
    }
}
